package com.philosophy.web.domain.generate;

import lombok.Data;

import java.time.LocalDateTime;
import java.util.Random;

/**
 * @author philosophy
 */
@Data
public class UrlMapping {

    /**
     * 默认的有效时间为一个月
     */
    private static final int DEFAULT_RANDOM_INTERVAL = 24 * 60 * 60;

    private static final Random RANDOM = new Random();

    public UrlMapping() {
    }

    public UrlMapping(String shortUrl, String originUrl, String salt) {
        this.shortUrl = shortUrl;
        this.originUrl = originUrl;
        this.salt = salt;
        this.startTimestamp = LocalDateTime.now();
        this.endTimestamp = startTimestamp.plusMonths(1).plusSeconds(RANDOM.nextInt(DEFAULT_RANDOM_INTERVAL));
    }

    /**
     * id
     */
    private Long id;

    /**
     * 长链接
     */
    private String originUrl;

    /**
     * 长链接
     */
    private String shortUrl;

    /**
     * 加盐
     */
    private String salt;

    /**
     * url的开始有效时间
     */
    private LocalDateTime startTimestamp;

    /**
     * url的结束有效时间
     */
    private LocalDateTime endTimestamp;
}
